home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Connection Tool ƒ / Setup.c < prev    next >
C/C++ Source or Header  |  1994-02-19  |  6KB  |  196 lines

  1. // ===========================================================================
  2. // "Connection Tool Skeleton in C" for the Communications Toolbox
  3. // 
  4. //    Copyright © 1994 Peter J. Creath
  5. //    All Rights Reserved Worldwide
  6. // ===========================================================================
  7.  
  8. #include "ConnToolCommon.h"
  9.  
  10. // ===========================================================================
  11. // Function prototypes
  12. // ===========================================================================
  13. extern pascal long    main(CMSetupPtr pSetup, short msg, Ptr pParam1, short *pItem, PrivatePtr *pPrivate);
  14. extern long    DoPreflight(CMSetupPtr pSetup, PrivatePtr *hPrivate);
  15. extern void    DoSetup(CMSetupPtr pSetup);
  16. extern void    DoItem(CMSetupPtr pSetup, PrivatePtr pPrivate, short *pItem);
  17. extern long    DoFilter(CMSetupPtr pSetup, PrivatePtr pPrivate, EventRecord *pEvent, short *pItem);
  18. extern void    DoCleanup(Ptr *thePtr);
  19.  
  20.  
  21. // ===========================================================================
  22. // main()
  23. //     This function is the entry point for the 'cset' resource.  It passes control to the appropriate
  24. //     subroutines, depending on the incoming message.  This can probably remain unchanged.
  25. // ===========================================================================
  26.  
  27. pascal long main(CMSetupPtr pSetup, short msg, Ptr pParam1, short *pItem, PrivatePtr *pPrivate)
  28. {
  29. long    rtnValue;
  30.  
  31.     switch (msg)
  32.         {
  33.             case cmSpreflightMsg:                                                            // Initialize private data storage
  34.                 rtnValue = DoPreflight(pSetup, pPrivate);
  35.                 break;
  36.                 
  37.             case cmSsetupMsg:                                                                // Set up the configuration dialog
  38.                 DoSetup(pSetup);
  39.                 break;
  40.                 
  41.             case cmSitemMsg:                                                                // Handle any clicked items in the dialog
  42.                 DoItem(pSetup, *pPrivate, (short *)pParam1);    
  43.                 break;
  44.                 
  45.             case cmSfilterMsg:                                                                // Filter events to the dialog
  46.                 rtnValue = DoFilter(pSetup, *pPrivate, (EventRecord *)pParam1, pItem);
  47.                 break;
  48.                 
  49.             case cmScleanupMsg:                                                            // Deallocate private data storage
  50.                 DoCleanup((Ptr *)pPrivate);
  51.                 break;
  52.                 
  53.             default:                                                                                    // Say what?
  54.                 rtnValue = cmNotSupported;
  55.                 break;
  56.         }
  57.  
  58. return (rtnValue);
  59. }
  60.  
  61.  
  62. // ===========================================================================
  63. // DoPreflight()
  64. //     This function is called in response to a cmSpreflightMsg.  It should allocate and initialize the
  65. //     PrivateRecord structure (or just use long in place of the pointer, if no more data is required).
  66. //     It should then return a handle to a dialog item list, which the caller of this tool should dispose of.
  67. // ===========================================================================
  68.  
  69. long DoPreflight(CMSetupPtr pSetup, PrivatePtr *hPrivate)
  70. {
  71. Handle            hDITL;
  72. short            theID;
  73. short            oldResRef;
  74. long                rtnValue;
  75. PrivatePtr    pPrivate;
  76.  
  77.     pPrivate = (PrivatePtr)NewPtr(sizeof(PrivateRecord));        // Allocate new private data storage
  78.     pPrivate->foobar = 0;                                                            // and initialize it
  79.     *hPrivate = pPrivate;                                                            // Pass its address back up the chain
  80.  
  81.     theID = CRMLocalToRealID(classCM, pSetup->procID, 'DITL', localDITLID);
  82.     if (theID == -1)
  83.         {
  84.             rtnValue = FALSE;                                                            // No DITL found
  85.         }
  86.     else
  87.         {
  88.             oldResRef = CurResFile();
  89.             UseResFile(pSetup->procID);                                            // procID is the tool's resource refnum
  90.             hDITL = Get1Resource('DITL', theID);                                // Grab the DITL
  91.             UseResFile(oldResRef);
  92.             
  93.             if (hDITL)
  94.                 {
  95.                     DetachResource(hDITL);                                        // Detach it from the resource file
  96.                 }
  97.             
  98.             rtnValue = (long)hDITL;                                                    // Return the handle
  99.         }
  100.  
  101. return (rtnValue);
  102. }
  103.  
  104.  
  105. // ===========================================================================
  106. // DoSetup()
  107. //     This subroutine is called in response to a cmSetupMsg.  It should set up the setup dialog's controls
  108. //     based on the current data in the ConfigRecord.
  109. // ===========================================================================
  110.  
  111. void    DoSetup(CMSetupPtr pSetup)
  112. {
  113. short            first;
  114. ConfigPtr        pConfig;
  115. Handle            itemHandle;
  116. short            itemKind;
  117. Rect                itemRect;
  118.  
  119.     first = pSetup->count - 1;                                                    // count is 1-based
  120.     pConfig = (ConfigPtr)(pSetup->theConfig);                            // get the config ptr
  121.     
  122.     GetDItem(pSetup->theDialog, first + myFirstItem, &itemKind, &itemHandle, &itemRect);
  123.     SetCtlValue((ControlHandle)itemHandle, pConfig->foobar);
  124.     GetDItem(pSetup->theDialog, first + mySecondItem, &itemKind, &itemHandle, &itemRect);
  125.     SetCtlValue((ControlHandle)itemHandle, 1-pConfig->foobar);
  126. }
  127.  
  128.  
  129. // ===========================================================================
  130. // DoItem()
  131. //     This subroutine is called in response to a cmSitemMsg.  It should handle any item clicks on the
  132. //     setup dialog.
  133. // ===========================================================================
  134.  
  135. void    DoItem(CMSetupPtr pSetup, PrivatePtr pPrivate, short *pItem)
  136. {
  137. short            value;
  138. short            first;
  139. ConfigPtr        pConfig;
  140. Handle            itemHandle;
  141. short            itemKind;
  142. Rect                itemRect;
  143.  
  144.     first = pSetup->count - 1;                                                    // count is 1-based
  145.     pConfig = (ConfigPtr)(pSetup->theConfig);                            // get the config ptr
  146.     
  147.     switch (*pItem - first)
  148.         {
  149.             case myFirstItem:
  150.                 GetDItem(pSetup->theDialog, first + myFirstItem, &itemKind, &itemHandle, &itemRect);
  151.                 value = 1 - GetCtlValue((ControlHandle)itemHandle);
  152.                 pConfig->foobar = value;                                        // stick value into config record
  153.                 SetCtlValue((ControlHandle)itemHandle, value);        // update control
  154.                 break;
  155.  
  156.             case mySecondItem:
  157.                 SysBeep(5);
  158.                 FlashMenuBar(0);
  159.                 break;
  160.         }
  161. }
  162.  
  163.  
  164. // ===========================================================================
  165. // DoFilter()
  166. //     This function is called in response to a cmSfilterMsg.  It acts as the filter routine would in a
  167. //     modal dialog.  It should return TRUE if the event was handled, or FALSE if not.
  168. // ===========================================================================
  169.  
  170. long    DoFilter(CMSetupPtr pSetup, PrivatePtr pPrivate, EventRecord *pEvent, short *pItem)
  171. {
  172. long    rtnValue;
  173.  
  174.     rtnValue = FALSE;
  175.     if (pEvent->what == keyDown)
  176.         {
  177.             SysBeep(5);
  178.             rtnValue = TRUE;
  179.         }
  180.         
  181. return (rtnValue);
  182. }
  183.  
  184.  
  185. // ===========================================================================
  186. // DoCleanup()
  187. //     This subroutine is called in response to a cmScleanupMsg.  It should clean up any private data
  188. //     storage allocated in DoPreflight().
  189. // ===========================================================================
  190.  
  191. void    DoCleanup(Ptr *thePtr)
  192. {
  193.     DisposPtr(*thePtr);
  194.     *thePtr = (Ptr)0L;
  195. }
  196.